import {
	getWxUserInfo
} from '@/common/api/auth'

const user = {
	state: {
		userInfo: {
			nickname: null,
			avatar: null,
			hasLogin: false
		}
	},
	getters: {
		getUserInfo(state) {
			return state.userInfo;
		}
	},
	mutations: {
		SET_TOKEN: (state, token) => {
			state.token = token
		},
		SET_AVATAR: (state, avatar) => {
			state.avatar = avatar
		},
		SET_ROLES: (state, roles) => {
			state.roles = roles
		},
		SET_USERINFO: (state, userInfo) => {
			state.userInfo = userInfo
		}
	},
	actions: {
		hasLogin() {
			const token = uni.getStorageSync('token');
			if (this.$s.isNotBlank(token)) {
				return true;
			}
			return false;
		},
		login({
			commit
		}, e) {
			login(e).then(res => {
				commit(login, res)
			})
		},
		getUserInfo({
			commit
		}, e) {
			SET_USERINFO(e)
		}

	}
}

export default user
